package com.bao.system.controller;


import com.bao.response.Result;
import com.bao.system.entity.Effect;
import com.bao.system.service.EffectService;
import com.bao.vo.EffectVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author bao
 * @since 2021-06-10
 */
@RestController
@RequestMapping("/system/effect")
//@CrossOrigin
public class EffectController {

    @Autowired
    EffectService effectService;

    @PostMapping("/findEffectPage")
    @ApiOperation(value = "查询所有用户信息",notes = "查询所有用户")
    public Result findEffectPage(@RequestParam(required = true, defaultValue = "1") Integer currentPage,
                                 @RequestParam(required = true, defaultValue = "7") Integer pageSize,
                                 @RequestBody EffectVO effectVO){
        System.out.println("------------------------");
        System.out.println(effectVO);
        System.out.println(currentPage +"-"+ pageSize);
        Page<Effect> page = new Page<Effect>(currentPage, pageSize);
        IPage<Effect> effectPage = effectService.findEffectPage(page, effectVO);
        long total = effectPage.getTotal();
        List<Effect> effectList = effectPage.getRecords();
        System.out.println(effectList);
        return Result.ok().data("total",total).data("effectList",effectList);
    }

    @GetMapping("/deleEffet")
    @ApiOperation(value = "删除效应",notes = "查询所有用户")
    public Result deleEffet(@RequestParam Integer id){
        System.out.println(id);
        effectService.deleEffet(id);
        return Result.ok();
    }

    @GetMapping("/addEffect")
    @ApiOperation(value = "删除效应",notes = "查询所有用户")
    public Result addEffect(Effect effect){
        System.out.println(effect);
        effect.setCreatetime(new Date());
        effectService.addEffect(effect);
        return Result.ok();
    }

    @GetMapping("/examineEffect")
    @ApiOperation(value = "删除效应",notes = "查询所有用户")
    public Result examineEffect(@RequestParam Integer id){
        System.out.println(id);
        effectService.examineEffect(id);
        return Result.ok();
    }

}

